/**
 * 设置详情页是否有变化
 * @param state
 * @param {boolean} value
 * @constructor
 */
function SetHasDetailChange(state, value) {
  state.hasDetailChange = value
}

// 设置列表数据
// function initList (state, obj) {
//   state[obj.module].listData = obj.data || {}
// }

// 设置详情数据
// function initDetail (state, obj) {
//   state[obj.module].detailData = obj.data || {}
// }

/**
 * 设置刷新状态
 * @param state
 * @param {Boolean} status
 * @constructor
 */
function SetRefresh (state, status) {
  if (typeof status === 'boolean') {
    state.isRefresh = status
  }
}

// 处理树形
function getTreeList(state, obj) {
  state.treeList = obj || []
}

// 修改全局加载状态
function isLoading (state, status) {
  if (typeof status === 'boolean') {
    state.isLoading = status
  }
}

// 修改保存状态
function SetSaveState (state, status) {
  if (typeof status === 'boolean') {
    state.saveState = status
  }
}

// 修改指定模块State的值
function SetState(state, obj) {
  if (obj.module) {
    state[obj.module][obj.state] = obj.data || ''
  } else {
    state[obj.state] = obj.data || ''
  }
}

// 修改指定模块字典的值
function SetDict(state, obj) {
  Object.assign(state[obj.module], obj.data)
}
// 修改未读消息数量
function SetUnreadNumber(state, number) {
  state.unreadMessageNumber = number
}
// 修改用户信息
function SetUserInfo(state, info) {
  state.userInfo = info
}
// 设置导航栏权限
function SetTree(state, tree) {
  state.userTree = tree
}

/**
 * @desc 设置按钮权限
 * @param state
 * @param buttonPermissions 按钮权限
 * @constructor
 */
function SetButtonPermissions(state, buttonPermissions) {
  state.buttonPermissions = buttonPermissions
}

// 将mutations 方法暴露到全局
export default {
  SetHasDetailChange,
  SetRefresh,
  SetSaveState,
  // initList,
  // initDetail,
  getTreeList,
  isLoading,
  SetState,
  SetDict,
  SetUnreadNumber,
  SetUserInfo,
  SetTree,
  SetButtonPermissions,
}
